from sklearn.datasets import load_digits
from sklearn.feature_selection import chi2
import pandas as pd

data = load_digits()
X, y = data.data, data.target
# print(X)

chi2_scores, p_values = chi2(X, y)
print(chi2_scores,p_values)
# 打印每个特征的卡方统计量和p值
print(X.shape[1])
df_chi2 = pd.DataFrame({'Feature': range(X.shape[1]), 'Chi2 Score': chi2_scores, 'p-value': p_values})
print("\nChi2 statistics for each feature:")
print(df_chi2.head())